// pages/setting/setting.js
const systemInfo = wx.getWindowInfo();
const bottomInset = Math.abs(systemInfo.safeArea.bottom - systemInfo.windowHeight);    

Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      bottomInset: bottomInset
    });
  },
  //点击个人资料
  actionPersonInfo() {
    if (this.userLoginStatus()) {
      wx.navigateTo({
        url: '/pages/person/personInfo',
      })
    }
  },
  //修改密码
  actionPassword() {
    wx.navigateTo({
      url: '/pages/setting/editPassword',
    })
  },
  //黑名单管理
  actionBlackList() {
    if (wx.getStorageSync('USERDATA')) {
      wx.navigateTo({
        url: '/pages/setting/blackList',
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '需要登录后体验其他功能',
        complete: (res) => {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/login/login',
            })
          }
        }
      });
    }

  },
  //判断用户是否登录,未登录弹出登录框
  userLoginStatus() {
    if (wx.getStorageSync('USERDATA')) {
      return true;
    } else {
      wx.showModal({
        title: '提示',
        content: '需要登录后体验其他功能',
        complete: (res) => {
          if (res.confirm) {
            wx.navigateTo({
              url: '/pages/login/login',
            })
          }
        }
      });
      return false;
    }
  },
  //联系客服
  actionKefu() {
    wx.openCustomerServiceChat({
      corpId: 'ww1a67d4324104daaa',
      extInfo: {
        url: 'https://work.weixin.qq.com/kfid/kfc967f9513998cc218',
      },
    })
  },
  //退出登录
  actionLogout() {
    wx.showModal({
      title: '提示',
      content: '是否要退出当前账号？',
      confirmText: '退出',
      complete: (res) => {
        if (res.confirm) {
          wx.setStorageSync('USERDATA', null);
          wx.navigateBack({
            delta: 0,
          });
        }
      }
    });
  }
})